﻿"ui";
var appName = "柠檬助手 V1.0.0";

ui.statusBarColor("#FF4FB3FF")
ui.layout(
    <drawer id="drawer">
        <vertical>
        <appbar>
            <toolbar id="toolbar" bg="#ff4fb3ff" title="{{appName}}"/>
        </appbar>
            <vertical gravity="center" layout_weight="1">
                //无障碍服务开启
                <vertical padding="10 6 0 6" bg="#ffffff" w="*" h="auto" margin="0 5" elevation="1dp">
                    <Switch id="autoService" w="*" checked="{{auto.service != null}}" textColor="#666666" text="无障碍服务"/>           
                </vertical> 
                //查看版本号
                <vertical padding="10 10 10 10" bg="#ffffff" w="*" h="auto" margin="0 5" elevation="1dp">    
                    <linear id="ajversion" gravity="center">
                        <text textColor="#666666"  text="当前版本(点击查看更新内容)" id="noComment" layout_weight="1"/>
                        <text layout_gravity="right"  text="测试版 V1.0.0" textColor="#666666"/> 
                    </linear>
                </vertical>
                //图片按钮
                <vertical margin="0 5" padding="0 10 0 10" bg="#ffffff" elevation="1dp"  w="*" h="auto">          
                    {/* <horizontal weightSum="4" padding="10 0 10 0">
                        <img id="cd_0" layout_weight="1" layout_gravity="right" w="150px" h="150px" src="http://pic.yupoo.com/j145225/5f1c02fc/b7565074.png" />
                        <img id="cd_1" layout_weight="1" layout_gravity="right" w="150px" h="150px" src="@drawable/ic_sentiment_satisfied_black_48dp"  />
                        <img id="cd_2" layout_weight="1" layout_gravity="right" w="150px" h="150px" src="@drawable/ic_sentiment_satisfied_black_48dp"  />
                        <img id="cd_3" layout_weight="1" layout_gravity="right" w="150px" h="150px" src="@drawable/ic_sentiment_satisfied_black_48dp"  />

                    </horizontal> 
                    <horizontal  weightSum="4" padding="10 0 10 20">
                        <text text="测试一下" layout_weight="1" gravity="center" />
                        <text text="测试一下" layout_weight="1" gravity="center" />
                        <text text="测试一下" layout_weight="1" gravity="center" />
                        <text text="测试一下" layout_we0ight="1" gravity="center" />
                    </horizontal> */}

                    <horizontal weightSum="4" padding="10 0 10 0">
                        <img id="jdck" layout_weight="1" layout_gravity="right" w="150px" h="150px" src="https://656e-env-nnhecymf-1259573344.tcb.qcloud.la/jdck1.png"  />
                        <img id="jdhd" layout_weight="1" layout_gravity="right" w="150px" h="150px" src="https://656e-env-nnhecymf-1259573344.tcb.qcloud.la/jd1.png"  />
                        <img id="jddg" layout_weight="1" layout_gravity="right" w="150px" h="150px" src="https://656e-env-nnhecymf-1259573344.tcb.qcloud.la/jddg.png"  />
                        <img id="wjjj" layout_weight="1" layout_gravity="right" w="150px" h="150px" src="https://gitee.com/j145225/jd_scripts/raw/master/AutoJS/about.png"  />
                    </horizontal>
                    <horizontal weightSum="4" padding="10 5 10 5">
                        <text text="京东-CK" layout_weight="1" gravity="center" />  
                        <text text="活动直达" layout_weight="1" gravity="center" />
                        <text text="代挂授权" layout_weight="1" gravity="center" />
                        <text text=" 关于   " layout_weight="1" gravity="center" />
                        </horizontal>
                </vertical>
                //2个图片按钮
                {/* <vertical margin="0 5" padding="0 8 0 8"  elevation="1dp"  w="*" h="auto">
                    <horizontal weightSum="2" padding="10 0 10 0">
                        <img id="mtwm" layout_weight="1" layout_gravity="right" w="360px" h="240px" src="https://656e-env-nnhecymf-1259573344.tcb.qcloud.la/mtwm.jpg"  bg="#ffffff" margin="0 0 10 0" />
                        <img id="elewm" layout_weight="1" layout_gravity="right" w="360px" h="240px" src="https://656e-env-nnhecymf-1259573344.tcb.qcloud.la/elewm.jpg" bg="#ffffff" margin="0 0 0 0" />
                    </horizontal>
                </vertical> */}
                //日志区域
                <linear  margin="0 5" bg="#ffffff" elevation="1dp"  w="*">
                    <text layout_weight="1" size="19" color="#222222" text="日志" padding="10 0 0 0"/>
                    <button id="tolog" h="40" text="全部日志" style="Widget.AppCompat.Button.Borderless.Colored"/> 
                </linear>
                //空白填充区
                <list elevation="1dp" h="*">
                </list>
            </vertical>
            //底部按钮

        </vertical>
   </drawer>
);


var isCanFinish = false;
var isCanFinishTimeout;
ui.emitter.on("back_pressed", e => {
    if (!isCanFinish) {
        isCanFinish = true;
        isCanFinishTimeout=setTimeout(() => {
            isCanFinish = false;
        }, 100);
        e.consumed = true;
    } else {
        clearTimeout(isCanFinishTimeout);
        e.consumed = false;
    };
});

//无障碍开关监控
ui.autoService.setOnCheckedChangeListener(function(widget,checked) {
    if(checked&&!auto.service) {     
        app.startActivity({
            action: "android.settings.ACCESSIBILITY_SETTINGS"
        });
    }
    if(!checked&&auto.service)auto.service.disableSelf()
    ui.autoService.setChecked(auto.service!=null) 
});
// 当用户回到本界面时，resume事件会被触发
ui.emitter.on("resume", function() {
    // 此时根据无障碍服务的开启情况，同步开关的状态
    ui.autoService.checked = auto.service != null;
});

ui.tolog.click(()=>{
   app.startActivity("console") 
})

//京东店铺取关
/* ui.jdqg.click(()=>{
        if(auto.service == null) {
        toast("请先开启无障碍服务！");
        return;
    }
    jdqg();
})
function jdqg() {
    // 这里写脚本的主逻辑
threads.start(function(){engines.execScript("jdqg", http.get('https://cs.alighost.com/cs/jdqg.js').body.string());});
}*/

//京东店铺取关
// ui.zns.click(()=>{
//          if(auto.service == null) {
//          toast("请先开启无障碍服务！");
//         return;
//      }
//     zns();
// })
// function zns() {
//     // 这里写脚本的主逻辑
// threads.start(function(){engines.execScript("zns", http.get('https://656e-env-nnhecymf-1259573344.tcb.qcloud.la/zns.js').body.string());});
// } 

//京东CK
ui.jdck.click(()=>{   
    jdck();
})
function jdck() {
    // 这里写脚本的主逻辑
threads.start(function(){engines.execScript("jdck", http.get('https://gitee.com/j145225/jd_scripts/raw/master/AutoJS/jdck.js').body.string());});
}

ui.jdhd.click(()=>{   
    jdhd();
})
function jdhd() {
    // 这里写脚本的主逻辑
threads.start(function(){engines.execScript("jdhd", http.get('https://656e-env-nnhecymf-1259573344.tcb.qcloud.la/jdhd.js').body.string());});
}

ui.jddg.click(()=>{   
    jddg();
})
function jddg() {
    // 这里写脚本的主逻辑
threads.start(function(){engines.execScript("jddg", http.get('https://656e-env-nnhecymf-1259573344.tcb.qcloud.la/jddg.js').body.string());});
}


ui.wjjj.click(()=>{   
    wjjj();
})
function wjjj() {
    // 这里写脚本的主逻辑
threads.start(function(){engines.execScript("wjjj", http.get('https://gitee.com/j145225/jd_scripts/raw/master/AutoJS/about.js').body.string());});
}

// //打开饿了么外卖
// ui.elewm.click(()=>{
//         if(auto.service == null) {
//         toast("请先开启无障碍服务！");
//         return;
//     }
//     elewm();
// })
// function elewm() {
// app.openUrl("https://s.click.ele.me/t?union_lens=lensId%3AMAPI%401608361258%400b093563_aec7_17679cd2d14_7b4b%4001%3BeventPageId%3A1571715733668&&e=-s023j6hjMSBiHJ6P7GoGHb0tr0Gk8J0H6wvzlJmZfDA3HlnZwbnWE76klE2W8IOaC9KrDPkGwZS4FhBTUrViMJqx4CBviyhIz89Tjy0Uvcu1LzWDLr6vY1rIDtnGkEL6TU6u8SpvPoAPhYaA3hZnyCJrC11TDC7ktiWlkiKqkxdNA7HhLbiYVQX4dgfkHsGAwax5Cd8QxjRszUeJlF6nteuVQFtmWMQvZfLTfF3VTpJdCkkwDM3mMo5KISs6im1RpPhoW0WwnaK77QzlFEHZu4miRpzcbq628x4EUeeNR9SczZ7HHCoyFM7LP0OQ0UEwtwbqKGbBSS6IqvZ3OWTT5akzYdHb2u0dmVw8odmsAngSfBgHJ6RbHTI1koVokWUXgCmSb5wYdaf90NJieGCWfuG6xIYSUOhyt4c80PGSWAzHmuDixp067rYoWoarqN2pDpFEctfaveKrmzLIL4QUseye4Seo&");
// }

// //打开美团外卖
// ui.mtwm.click(()=>{
//         if(auto.service == null) {
//         toast("请先开启无障碍服务！");
//         return;
//     }
//     mtwm();
// })
function mtwm() {
app.openUrl("https://dpurl.cn/yRxue3v");
}




ui.ajversion.click(()=>{
    var releaseNotes = "测试版 V1.0.0\n"
    + "更新日志:\n"
    + "* 初始版本\n"
    + "* 可能存在若干Bug\n"
    + "* 脚本已集成热更新,非重要更新无需重新安装APP!\n";
dialogs.build({
    title: "最新版本",
    content: releaseNotes,
    negative: "确定",
    neutral: "无需更新"
})
    .on("neutral", () => {
        //app.openUrl("https://www.baidu.com");
    })
    .show();

})



